package game.players.user;

import java.util.Timer;

import utils.tasks.FinishSweepWithBallTask;

import com.uqbar.vainilla.appearances.Sprite;

import game.players.SoccerPlayer;
import game.players.states.WithBallSweepingPlayer;
import game.players.user.movements.WithBallStationaryUser;

public class WithBallSweepingUserPlayer extends WithBallSweepingPlayer {
	
	private FinishSweepWithBallTask timerTask = new FinishSweepWithBallTask(this);

	public WithBallSweepingUserPlayer(SoccerPlayer player, boolean isRight) {
		super(player, isRight);
		
		Timer timer = new Timer();
		timer.schedule(this.getTimerTask() , 500);
	}
	
	@Override
	protected void setRightSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5));
	}
	
	@Override
	protected void setLeftSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5).flipHorizontally());
	}

	@Override
	public void loseTheBall() {
		this.getTimerTask().cancel();
		this.getPlayer().setState(new BeatenUserPlayer(this.getPlayer(), this.isRight()));
	}
	
	public void finishSweep() {
		this.getPlayer().addUserPlayerMark();
		this.getPlayer().setState(new WithBallStationaryUser(this.getPlayer()));
	}
	
	public FinishSweepWithBallTask getTimerTask() {
		return timerTask;
	}
}
